<!--#include file="conn.asp"-->
<!--#include file="chkuser.asp"-->
<%
dim rs,sql,ErrMsg,FoundErr,delfilemsg
dim OneClassID,TwoClassID,ThreeClassID
dim ArticleID,newsclass,title,subtitle,Content,publisher,Show
dim pic,DefaultPicUrl,UploadFiles,s,arrUploadFiles,AddDate
dim ObjInstalled
ObjInstalled=IsObjInstalled("Scripting.FileSystemObject")
FoundErr=false

ArticleID=Trim(Request("ArticleID"))
OneClassID=Trim(request("OneClassID"))
TwoClassID=Trim(request("TwoClassID"))
ThreeClassID=Trim(request("ThreeClassID"))
Title=Replace_Text(request("Title"))
subTitle=Replace_Text(request("subTitle"))
Content=Trim(request("Content"))
publisher=Trim(request("publisher"))
Show=Trim(request("Show"))
pic=Trim(request("pic"))
AddDate=Trim(request("AddDate"))
DefaultPicUrl=Trim(request("DefaultPicUrl"))
UploadFiles=Trim(request("UploadFiles"))
if Show="" then Show=False
'使内容内的图片路径转为正确的相对路径
Content=replace(Content,"="&chr(34)&"./../","="&chr(34)&"./")

if OneClassID="" then OneClassID=0
if TwoClassID="" then TwoClassID=0
if ThreeClassID="" then ThreeClassID=0
set rs=server.createobject("adodb.recordset")
if request("action")="add" then
	sql="select * from News" 
	rs.open sql,conn,1,3
	rs.addnew
	call SaveData()		
	rs.update
	ArticleID=rs("ID")
	rs.close
	set rs=nothing
elseif request("action")="Modify" then
	if ArticleID<>"" then
		sql="select * from News where ID=" & ArticleID
		rs.open sql,conn,1,3
		if not (rs.bof and rs.eof) then
			if	rs("pic")<>pic then call DelFile("../"&rs("pic"))
			call SaveData()
			rs.update
			rs.close
			set rs=nothing
		else
			founderr=true
			errmsg=errmsg+"<p style=font-size:14px;color:red>找不到此信息，可能已经被删除。</p>"
			call WriteErrMsg(ErrMsg)
		end if
	else
		founderr=true
		errmsg=errmsg+"<p style=font-size:14px;color:red>不能确定ArticleID的值</p>"
		call WriteErrMsg(ErrMsg)
	end if
else
	founderr=true
	errmsg=errmsg+"<p style=font-size:14px;color:red>没有选定参数</p>"
	call WriteErrMsg(ErrMsg)
end if

sub SaveData()
	rs("OneClassID")=OneClassID
	rs("TwoClassID")=TwoClassID
	rs("ThreeClassID")=ThreeClassID
	rs("Title")=Title
	rs("subTitle")=subTitle
	rs("Content")=Content
	rs("Publisher")=publisher
	rs("Show")=Show
	rs("AddDate")=AddDate
	'***************************************
	'删除无用的上传文件
	if ObjInstalled=True and UploadFiles<>"" then
		if instr(UploadFiles,"|")>1 then
			dim arrUploadFiles,intTemp
			arrUploadFiles=split(UploadFiles,"|")
			UploadFiles=""
			for intTemp=0 to ubound(arrUploadFiles)
				if instr(Content,arrUploadFiles(intTemp))<=0 and arrUploadFiles(intTemp)<>DefaultPicUrl then
					if DelFile("../" & arrUploadFiles(intTemp))=True then
						delfilemsg = delfilemsg & "<p style=font-size:12px;color:red>" & arrUploadFiles(intTemp) & "在文章中没有用到，也没有被设为首页图片，所以已经被删除!</p>"
					end if
				else
					if UploadFiles="" then
						UploadFiles=arrUploadFiles(intTemp)
					else
						UploadFiles=UploadFiles & "|" & arrUploadFiles(intTemp)
					end if
				end if
			next
		else
			if instr(Content,UploadFiles)<=0 and UploadFiles<>DefaultPicUrl then
				if DelFile("../" & UploadFiles)=True then
					delfilemsg = delfilemsg &"<p style=font-size:12px;color:red>" & UploadFiles & "在文章中没有用到，也没有被设为首页图片，所以已经被删除!</p>"
				end if
				UploadFiles=""
			end if
		end if
	end If
	'结束
	'***************************************
	rs("DefaultPicUrl")=DefaultPicUrl
	rs("UploadFiles")=UploadFiles
	rs("pic")=pic
end sub
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td style="padding:120px 0">
      <table width="70%" border="0" cellpadding="4" cellspacing="0" align="center" class="tableTdBorder">
        <tr bgcolor="#efefef"> 
          <td height="25" colspan="2" align="center"><b> 
            <%if request("action")="add" then%>
            添加 
            <%else%>
            修改 
            <%end if%>
          文章成功</b></td>
        </tr>
        <tr> 
          <td width="25%" align="right">文章序号：</td>
          <td><%=ArticleID%></td>
        </tr>
        <tr> 
          <td align="right">文章标题：</td>
          <td><%=Title%></td>
        </tr>
		<%if NewsClassSD_con>0 then%>
        <tr> 
          <td align="right">所属类别：</td>
          <td>
		    <%
			arrClassID=array(OneClassID,TwoClassID,ThreeClassID)
			strClassName=""
			for arrClassID_i=0 to ubound(arrClassID)
			if arrClassID(arrClassID_i)=0 then exit for
				set rsc=server.CreateObject("adodb.recordset")
				sqlc="select * from newsclass where id="&arrClassID(arrClassID_i)
				rsc.open sqlc,conn,1,1
				if rsc.eof then exit for
					if strClassName="" then
						strClassName=rsc("classname")
					else
						strClassName=strClassName&" <font color='#ff0000'>&gt;&gt;</font> "&rsc("classname")
					end if
				rsc.close
				set rsc=nothing
			next
			if strClassName="" then strClassName="请选择类别"
			%><%=strClassName%></td>
        </tr>
		<%end if%>
        <tr> 
          <td colspan="2"> <div align="center"> 
          【<a href="Admin_News_Edit.asp?ArticleID=<%=ArticleID%>" style="color:#000000; text-decoration:none">修改信息</a>】
          &nbsp;
          【<a href="Admin_News_Add.asp?OneClassID=<%=OneClassID%>&TwoClassID=<%=TwoClassID%>&ThreeClassID=<%=ThreeClassID%>" style="color:#000000; text-decoration:none">继续添加信息</a>】
          &nbsp;
          【<a href="Admin_News.asp" style="color:#000000; text-decoration:none">信息管理</a>】
          </div></td>
        </tr>
		<%if delfilemsg<>"" then%>
        <tr> 
          <td colspan="2"><%=delfilemsg%></td>
        </tr>
		<%end if%>
      </table>
		<%
		if request("action")="add" then
			call ShowMessage("<br><b>文章信息已添加成功！<br>标题："&Title&"</b>","parent",3000,500,"","")
		else
			call ShowMessage("<br><b>文章信息已修改成功！<br>标题："&Title&"</b>","parent",3000,500,"","")
		end if
		%>
	</td>
  </tr>
</table>
</body>
</html>